package com.sam.im.heiqun.uis.adapters;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.google.gson.Gson;
import com.melink.bqmmsdk.widget.BQMMMessageText;
import com.sam.im.heiqun.R;
import com.sam.im.heiqun.constant.Constant;
import com.sam.im.heiqun.entities.AAentivity;
import com.sam.im.heiqun.entities.FanYiBean;
import com.sam.im.heiqun.entities.FileMsgEntivity;
import com.sam.im.heiqun.entities.GroupFriendEntivity;
import com.sam.im.heiqun.entities.ImFriendEntivity;
import com.sam.im.heiqun.entities.ImGroupEntivity;
import com.sam.im.heiqun.entities.ImMessage;
import com.sam.im.heiqun.entities.ImageSendEntity;
import com.sam.im.heiqun.entities.LuckyRedEnvelopeEntivity;
import com.sam.im.heiqun.entities.MsgEntity;
import com.sam.im.heiqun.entities.PathEntivity;
import com.sam.im.heiqun.entities.RedPacketEntivity;
import com.sam.im.heiqun.entities.TransferEntivity;
import com.sam.im.heiqun.entities.VedioEntity;
import com.sam.im.heiqun.entities.beans.ImageInfoBean;
import com.sam.im.heiqun.entities.model.LocationEntivity;
import com.sam.im.heiqun.uis.activities.AAActivity;
import com.sam.im.heiqun.uis.activities.FriendDetailActivity;
import com.sam.im.heiqun.uis.activities.ImagePagerActivity;
import com.sam.im.heiqun.uis.activities.LuckyRedEnvelopeActivity;
import com.sam.im.heiqun.uis.activities.ToLocationActivity;
import com.sam.im.heiqun.uis.beans.FriendmpBean;
import com.sam.im.heiqun.uis.widgets.BubbleImageView;
import com.sam.im.heiqun.uis.widgets.GifTextView;
import com.sam.im.heiqun.uis.widgets.MediaManager;
import com.sam.im.heiqun.utils.IMMessageUtil;
import com.sam.im.heiqun.utils.ImageSize;
import com.sam.im.heiqun.utils.JsonUtil;
import com.sam.im.heiqun.utils.MyBitmapUtil;
import com.sam.im.heiqun.utils.StringUtils;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.yuyh.library.utils.DimenUtils;
import com.yuyh.library.utils.GlideUtils;
import com.yuyh.library.utils.ScreenUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by Mao Jiqing on 2016/9/29.
 */
public class ChatGroupRecyclerAdapter extends
        RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener,View.OnLongClickListener {
    private static final String TAG = ChatGroupRecyclerAdapter.class.getSimpleName();
    private Context context;
    private List<ImMessage> userList = new ArrayList<ImMessage>();
    private ArrayList<ImageInfoBean> imageList = new ArrayList<>();
    private HashMap<Integer, Integer> imagePosition = new HashMap<Integer, Integer>();

    private ImGroupEntivity mImGroupEntivity;

    public void setGroupEntivity(ImGroupEntivity mImGroupEntivity) {
        this.mImGroupEntivity = mImGroupEntivity;
    }

    public static final int FROM_USER_MSG = 0;//接收文本消息类型
    public static final int TO_USER_MSG = 1;//发送文本消息类型
    public static final int FROM_USER_IMG = 2;//接收图片消息类型
    public static final int TO_USER_IMG = 3;//发送图片消息类型
    public static final int FROM_USER_VOICE = 4;//接收语音消息类型
    public static final int TO_USER_VOICE = 5;//发送语音消息类型
    public static final int FROM_USER_REDPACKET = 6;//接收红包消息类型
    public static final int TO_USER_REDPACKET = 7;//发送红包消息类型
    public static final int SHOW_PROMP_RED = 8;//红包领取的提示小框
    public static final int TO_USER_TRANSFER = 9;//发送转账消息
    public static final int FROM_USER_TRANSFER = 10;//接受转账消息
    public static final int FROM_USER_TRANSFER_OTHER_GET = 11;//转账被接受消息
    public static final int TO_USER_TRANSFER_OTHER_GET = 12;//发送转账被接受消息
    public static final int SHOW_TRANSFER_BACK = 13;//转账退回
    public static final int SHOW_REDPACKET_BACK = 14;//红包退回
    public static final int TO_USER_LOCATION = 15;//发位置
    public static final int FROM_USER_LOCATION = 16;//收位置
    public static final int TO_WITHDRAW_MSG = 17;//发送撤回
    public static final int FROM_WITHDRAW_MSG = 18;//收到撤回
    public static final int TO_USER_EMOJI = 19; //发表情、图文混排
    public static final int FROM_USER_EMOJI = 20;// 收表情、图文混排
    public static final int TO_USER_EMOJI_TEXT = 21;//图文混排
    public static final int FROM_USER_EMOJI_TEXT = 22;//图文混排
    public static final int TO_USER_FILE = 25;//发文件
    public static final int FROM_USER_FILE = 26;//收文件
    public static final int TO_USER_VEDIO = 27;//发小视屏
    public static final int FROM_USER_VEDIO = 28;//收小视屏
    public static final int SHOW_PROMP_JOIN_GROUP = 30;//有人加入群
    public static final int SHOW_PROMP_DELETE_GROUP = 31;//有人退出群
    public static final int SHOW_PROMP_REDPACKET_NOFINISH = 32;//红包被领完
    public static final int TO_USER_AA = 33;//发送AA收款
    public static final int FROM_USER_AA = 34;//收到AA收款
    public static final int TO_USER_READDELETE = 35;//发送阅后即焚
    public static final int FROM_USER_READDELETE = 36;//收到阅后即焚
    public static final int TO_USER_FRIEND_MP = 37;//发送名片
    public static final int FROM_USER_FRIEND_MP = 38;//接收名片
    public static final int SHOW_SET_MANAGER = 39; //设置管理员
    public static final int SHOW_CANCEL_MANAGER = 40;//取消管理员
    public static final int SHOW_BEAN_REMOVE = 41;//被移除群聊
    public static final int SHOW_BEAN_INVITED_JOIN_GROUP = 42;//被邀请进群
    public static final int Lucky_Red_Envelope = 43;//接收幸运红包
    public static final int Send_lucky_Red_Envelopes = 44;//发送幸运红包
    private int mMinItemWith;// 设置对话框的最大宽度和最小宽度
    private int mMaxItemWith;
    public Handler handler;
    private Animation an;
    private SendErrorListener sendErrorListener;
    private VoiceIsRead voiceIsRead;
    public List<String> unReadPosition = new ArrayList<String>();
    private int voicePlayPosition = -1;
    private LayoutInflater mLayoutInflater;
    private boolean isGif = true;
    public boolean isPicRefresh = true;
    private Handler mHandler;
    private RedPacketOnClick mRedPacketOnClick;
    private List<ImFriendEntivity> mFriendEntivities = new ArrayList<>();
    private FanYiOnClick mFanYiOnClick;
    private IItemHeadImageClickBack imageClickBack;
    private LayoutInflater inflater;
    private String friendnicknames;
    public onLongClickMsgListenler onlongclicklistenler;
    public onReadAiteListenler onReadAiteListenler;
    private OnclickDownloadListenler onclickDownloadListenler;
    private int progressint;
    private String progressstr;
    private String msgID;
    private OnTouchUplistener onTouchUplistener;

    public void setOnTouchUplistener(OnTouchUplistener onTouchUplistener) {
        this.onTouchUplistener = onTouchUplistener;
    }

    public void setProgressint(int progressint, String progressstr, String msgID) {
        this.progressint = progressint;
        this.msgID = msgID;
        this.progressstr = progressstr;
        notifyDataSetChanged();
    }

    public void setOnclickDownloadListenler(OnclickDownloadListenler onclickDownloadListenler) {
        this.onclickDownloadListenler = onclickDownloadListenler;
    }

    public void setOnReadAiteListenler(ChatGroupRecyclerAdapter.onReadAiteListenler onReadAiteListenler) {
        this.onReadAiteListenler = onReadAiteListenler;
    }

    public void setOnlongclicklistenler(onLongClickMsgListenler onlongclicklistenler) {
        this.onlongclicklistenler = onlongclicklistenler;
    }

    public void setFriendnicknames(String friendnicknames) {
        this.friendnicknames = friendnicknames;
    }

    public void setImageClickBack(IItemHeadImageClickBack imageClickBack) {
        this.imageClickBack = imageClickBack;
    }

    public void setImFriendEntivity(List<ImFriendEntivity> friendEntivities) {
        mFriendEntivities = friendEntivities;
    }

    @Override
    public boolean onLongClick(View v) {
        switch (v.getId()) {
            case R.id.tb_other_user_icon:

                if (imageClickBack != null) {
                    imageClickBack.headImageLongClick(v, ((Long) v.getTag(R.id.imageId)));
                }

                return true;
        }
        return false;
    }



    public interface SendErrorListener {
        public void onClick(int position);
    }

    public void setSendErrorListener(SendErrorListener sendErrorListener) {
        this.sendErrorListener = sendErrorListener;
    }

    public interface VoiceIsRead {
        public void voiceOnClick(int position);
    }

    public void setVoiceIsReadListener(VoiceIsRead voiceIsRead) {
        this.voiceIsRead = voiceIsRead;
    }

    public interface RedPacketOnClick {
        void redOnClick(ImMessage imMessage, int type);//0-获取；1-发送
    }

    public void setRedPacketListener(RedPacketOnClick redPacketOnClick) {
        this.mRedPacketOnClick = redPacketOnClick;
    }

    public void setFanYiListener(FanYiOnClick mFanYiOnClick) {
        this.mFanYiOnClick = mFanYiOnClick;
    }

    public interface FanYiOnClick {
        void fanYiOnClick(String content, int type, int isRefresh);//isRefresh=0-不是；1-是并显示；2-是并隐藏
    }

    public ChatGroupRecyclerAdapter(Context context, List<ImMessage> userList, onLongClickMsgListenler onlongclicklistenler) {
        //  EventBus.getDefault().register(this);
        this.context = context;
        this.userList = userList;
        this.inflater = LayoutInflater.from(context);
        this.onlongclicklistenler = onlongclicklistenler;
        mLayoutInflater = LayoutInflater.from(context);
        // 获取系统宽度
        WindowManager wManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wManager.getDefaultDisplay().getMetrics(outMetrics);
        mMaxItemWith = (int) (outMetrics.widthPixels * 0.5f);
        mMinItemWith = (int) (outMetrics.widthPixels * 0.15f);
        handler = new Handler();
    }

    public void setIsGif(boolean isGif) {
        this.isGif = isGif;
    }

    public void setImageList(ArrayList<ImageInfoBean> imageList) {
        this.imageList = imageList;
    }

    public void setImagePosition(HashMap<Integer, Integer> imagePosition) {
        this.imagePosition = imagePosition;
    }

    /**
     * @param parent
     * @param viewType
     * @return
     */
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        RecyclerView.ViewHolder holder = null;
        switch (viewType) {
            case FROM_USER_MSG:
                view = inflater.inflate(R.layout.layout_msgfrom_list_item, parent, false);
                holder = new FromUserMsgViewHolder(view);
                break;
            case FROM_USER_IMG:
                view = inflater.inflate(R.layout.layout_imagefrom_list_item, parent, false);
                holder = new FromUserImageViewHolder(view);
                break;
            case FROM_USER_VOICE:
                view = inflater.inflate(R.layout.layout_voicefrom_list_item, parent, false);
                holder = new FromUserVoiceViewHolder(view);
                break;
            case TO_USER_MSG:
                view = inflater.inflate(R.layout.layout_msgto_list_item, parent, false);
                holder = new ToUserMsgViewHolder(view);
                break;
            case TO_USER_IMG:
                view = inflater.inflate(R.layout.layout_imageto_list_item, parent, false);
                holder = new ToUserImgViewHolder(view);
                break;
            case TO_USER_LOCATION:
                view = inflater.inflate(R.layout.layout_locationto_list_item, parent, false);
                holder = new ToUserLocationViewHolder(view);
                break;
            case FROM_USER_LOCATION:
                view = inflater.inflate(R.layout.layout_locationfrom_list_item, parent, false);
                holder = new FromUserLocationViewHolder(view);
                break;
            case TO_USER_VOICE:
                view = inflater.inflate(R.layout.layout_voiceto_list_item, parent, false);
                holder = new ToUserVoiceViewHolder(view);
                break;
            case TO_USER_REDPACKET:
                view = inflater.inflate(R.layout.layout_redpacketto_list_item, parent, false);
                holder = new ToUserRedViewHolder(view);
                break;
            case Send_lucky_Red_Envelopes://发送幸运红包
                view = inflater.inflate(R.layout.activity_lucky_red_packet_sender, parent, false);
                holder = new LuckyRedPackSendingViewHolder(view);
                break;
            case FROM_USER_REDPACKET:
                view = inflater.inflate(R.layout.layout_redpacketfrom_list_item, parent, false);
                holder = new FromUserRedViewHolder(view);
                break;
            case Lucky_Red_Envelope://接收到幸运红包
                view = inflater.inflate(R.layout.adtivity_lucky_red_envelope_layout, parent, false);
                holder = new LuckyRedPackReceivingViewHolder(view);
                break;
            case TO_USER_TRANSFER:// 发送转账
                view = inflater.inflate(R.layout.layout_transferto_list_item, parent, false);
                holder = new ToUserTransferViewHolder(view);
                break;
            case FROM_USER_TRANSFER:// 接受转账
                view = inflater.inflate(R.layout.layout_transferfrom_list_item, parent, false);
                holder = new FromUserTransferViewHolder(view);
                break;
            case TO_USER_TRANSFER_OTHER_GET:// 发送转账bei接受
                view = inflater.inflate(R.layout.layout_transferto_list_item, parent, false);
                holder = new ToUserTransferViewHolder(view);
                break;
            case FROM_USER_TRANSFER_OTHER_GET:// 转账bei接受
                view = inflater.inflate(R.layout.layout_transferfrom_list_item, parent, false);
                holder = new FromUserTransferViewHolder(view);
                break;
            case SHOW_PROMP_RED:// 用于红包领取提示
            case SHOW_PROMP_JOIN_GROUP:// 有人加入群组
            case SHOW_PROMP_DELETE_GROUP:// 有人退出群组
            case SHOW_SET_MANAGER://设置管理员
            case SHOW_CANCEL_MANAGER://取消管理员
            case SHOW_BEAN_REMOVE:
            case SHOW_BEAN_INVITED_JOIN_GROUP:
                view = inflater.inflate(R.layout.layout_prompt_list_item, parent, false);
                holder = new PromptViewHolder(view);
                break;
            case SHOW_PROMP_REDPACKET_NOFINISH://
            case SHOW_TRANSFER_BACK:// 转账倍退回
            case SHOW_REDPACKET_BACK:// 红包倍退回
                view = inflater.inflate(R.layout.layout_prompt_list_item, parent, false);
                holder = new PromptViewHolder(view);
                break;
            case TO_WITHDRAW_MSG:
            case FROM_WITHDRAW_MSG:
                view = inflater.inflate(R.layout.layout_withdraw_item, parent, false);
                holder = new WithdrawViewholders(view);
                break;
            case TO_USER_EMOJI:
                view = inflater.inflate(R.layout.layout_emojito_list_item, parent, false);
                holder = new TouserEmojiViewHolder(view);
                break;
            case FROM_USER_EMOJI:
                view = inflater.inflate(R.layout.layout_emojifrom_list_item, parent, false);
                holder = new FromuserEmojiViewHolder(view);
                break;
            case TO_USER_EMOJI_TEXT://图文混排
                view = inflater.inflate(R.layout.layout_emojito_list_item, parent, false);
                holder = new TouserEmojitextViewHolder(view);
                break;
            case FROM_USER_EMOJI_TEXT://图文混排
                view = inflater.inflate(R.layout.layout_emojifrom_list_item, parent, false);
                holder = new FromuserEmojitextViewHolder(view);
                break;
            case TO_USER_FILE://发文件
                view = inflater.inflate(R.layout.layout_fileto_list_item, parent, false);
                holder = new TouserFileViewHolder(view);
                break;
            case FROM_USER_FILE://收文件
                view = inflater.inflate(R.layout.layout_filefrom_list_item, parent, false);
                holder = new FromuserFileViewHolder(view);
                break;
            case TO_USER_VEDIO://发小视屏
                view = inflater.inflate(R.layout.layout_vedioto_list_item, parent, false);
                holder = new TouserVedioViewHolder(view);
                break;
            case FROM_USER_VEDIO://收小视屏
                view = inflater.inflate(R.layout.layout_vediofrom_list_item, parent, false);
                holder = new FromuserVedioViewHolder(view);
                break;
            case TO_USER_AA: //AA收款
                view = inflater.inflate(R.layout.layout_aa_touser, parent, false);
                holder = new ToAaViewHolder(view);
                break;
            case FROM_USER_AA://AA付款
                view = inflater.inflate(R.layout.layout_aa_fromuser, parent, false);
                holder = new FromAaViewHolder(view);
                break;

            case TO_USER_READDELETE:
                view = inflater.inflate(R.layout.layout_readdeleteto_list_item, parent, false);
                holder = new ToreaddeleteHolder(view);
                break;
            case FROM_USER_READDELETE:
                view = inflater.inflate(R.layout.layout_readdeletefrom_list_item, parent, false);
                holder = new FromreaddeleteHolder(view);
                break;
            case TO_USER_FRIEND_MP://发送名片
                view = inflater.inflate(R.layout.layout_friend_mp_item, parent, false);//
                holder = new ChatGroupRecyclerAdapter.FriendMPViewHolder(view);
                break;
            case FROM_USER_FRIEND_MP://接收名片
                view = inflater.inflate(R.layout.layout_from_friend_mp_item, parent, false);//
                holder = new ChatGroupRecyclerAdapter.FriendMPFromViewHolder(view);
                break;
            default:
                view = inflater.inflate(R.layout.layout_withdraw_item, parent, false);//当有新类型添加时避免崩溃
                holder = new WithdrawViewholders(view);
                break;
        }
        return holder;
    }

    class ToreaddeleteHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private LinearLayout image_group;
        private BubbleImageView image_Msg;
        private ImageView sendFailImg;
        private TextView tvread;
        private TextView name;

        public ToreaddeleteHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            image_group = (LinearLayout) view
                    .findViewById(R.id.image_group);
            image_Msg = (BubbleImageView) view
                    .findViewById(R.id.image_message);
            tvread = (TextView) view.findViewById(R.id.tv_read);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    class FromreaddeleteHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private BubbleImageView image_Msg;
        private TextView name;

        public FromreaddeleteHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            image_Msg = (BubbleImageView) view
                    .findViewById(R.id.image_message);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    private class TouserFileViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private ImageView fileicon;
        private TextView tvFilename;
        private TextView tvFilesize;
        private TextView tvFileState;
        private ProgressBar progressBar;
        private TextView tvread;
        private ImageView sendFailImg;
        private RelativeLayout image_group;

        public TouserFileViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view.findViewById(R.id.mychat_time);
            fileicon = (ImageView) view.findViewById(R.id.file_icon);
            tvFilename = (TextView) view.findViewById(R.id.file_name);
            tvFilesize = (TextView) view.findViewById(R.id.file_size);
            tvFileState = (TextView) view.findViewById(R.id.file_state);
            progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
            tvread = (TextView) view.findViewById(R.id.tv_read);
            sendFailImg = (ImageView) view.findViewById(R.id.mysend_fail_img);
            image_group = (RelativeLayout) view.findViewById(R.id.image_group);
        }
    }

    private class FromuserFileViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private ImageView fileicon;
        private TextView tvFilename;
        private TextView tvFilesize;
        private TextView tvFileState;
        private ProgressBar progressBar;
        private TextView tvread;
        private RelativeLayout filelayout;
        private TextView name;

        public FromuserFileViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            fileicon = (ImageView) view.findViewById(R.id.file_icon);
            tvFilename = (TextView) view.findViewById(R.id.file_name);
            tvFilesize = (TextView) view.findViewById(R.id.file_size);
            tvFileState = (TextView) view.findViewById(R.id.file_state);
            progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
            tvread = (TextView) view.findViewById(R.id.tv_read);
            filelayout = (RelativeLayout) view.findViewById(R.id.relative_file);
            name = (TextView) view.findViewById(R.id.name);
        }
    }


    class FriendMPViewHolder extends RecyclerView.ViewHolder {
        private ImageView image_head;
        private TextView txt_name;
        private TextView txt_uid;
        private ImageView headicon;
        private TextView chat_time;

        private ImageView sendFailImg;
        private TextView tvread;
        private View imview;

        public FriendMPViewHolder(View view) {
            super(view);
            imview = view;
            headicon = (ImageView) itemView
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) itemView.findViewById(R.id.mychat_time);
            image_head = (ImageView) view.findViewById(R.id.image_head);
            txt_name = (TextView) view.findViewById(R.id.txt_name);
            txt_uid = (TextView) view.findViewById(R.id.txt_uid);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            tvread = (TextView) view.findViewById(R.id.tv_read);
        }
    }

    class FriendMPFromViewHolder extends RecyclerView.ViewHolder {
        private ImageView image_head;
        private TextView txt_name;
        private TextView txt_uid;
        private ImageView headicon;
        private TextView chat_time;
        private View imview;

        public FriendMPFromViewHolder(View view) {
            super(view);
            imview = view;
            headicon = (ImageView) itemView
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) itemView.findViewById(R.id.chat_time);
            image_head = (ImageView) view.findViewById(R.id.image_head);
            txt_name = (TextView) view.findViewById(R.id.txt_name);
            txt_uid = (TextView) view.findViewById(R.id.txt_uid);
        }
    }


    public interface OnclickDownloadListenler {
        void clickDown(int positon, int type);//type = 1  发送  type= 0 接收
    }

    private class TouserVedioViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private RelativeLayout image_group;
        private BubbleImageView image_Msg;
        private ImageView sendFailImg;
        private TextView tvread;
        private TextView tv_videotime;

        public TouserVedioViewHolder(View view) {
            super(view);

            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            image_group = (RelativeLayout) view
                    .findViewById(R.id.image_group);
            image_Msg = (BubbleImageView) view
                    .findViewById(R.id.image_message);
            tvread = (TextView) view.findViewById(R.id.tv_read);
            tv_videotime = (TextView) view.findViewById(R.id.tv_videotime);
        }

    }

    private class FromuserVedioViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private BubbleImageView image_Msg;
        private TextView tv_videotime;
        private TextView name;

        public FromuserVedioViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            image_Msg = (BubbleImageView) view
                    .findViewById(R.id.image_message);
            tv_videotime = (TextView) view.findViewById(R.id.tv_videotime);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    private class FromuserEmojitextViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private TextView button_fanyi;
        private BQMMMessageText content;
        private GifTextView content_fy;
        private TextView name;

        private LinearLayout linear_content;

        public FromuserEmojitextViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            button_fanyi = (TextView) view.findViewById(R.id.button_fanyi);
            content = (BQMMMessageText) view.findViewById(R.id.content);
            content_fy = (GifTextView) view.findViewById(R.id.content_fy);
            name = (TextView) view.findViewById(R.id.name);
            linear_content = (LinearLayout) view.findViewById(R.id.linear_content);
        }
    }

    class TouserEmojitextViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private BQMMMessageText content;
        private ImageView sendFailImg;

        public TouserEmojitextViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            content = (BQMMMessageText) view
                    .findViewById(R.id.mycontent);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
        }
    }

    private class FromuserEmojiViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        //  private TextView button_fanyi;
        private BQMMMessageText content;
        private GifTextView content_fy;
        private TextView name;
        private LinearLayout linear_content;

        public FromuserEmojiViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            //  button_fanyi = (TextView) view.findViewById(R.id.button_fanyi);
            content = (BQMMMessageText) view.findViewById(R.id.content);
            content_fy = (GifTextView) view.findViewById(R.id.content_fy);
            name = (TextView) view.findViewById(R.id.name);
            linear_content = (LinearLayout) view.findViewById(R.id.linear_content);
        }
    }

    class TouserEmojiViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private BQMMMessageText content;
        private ImageView sendFailImg;

        public TouserEmojiViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            content = (BQMMMessageText) view
                    .findViewById(R.id.mycontent);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
        }
    }

    private class WithdrawViewholders extends RecyclerView.ViewHolder {
        private TextView tvcontent;

        public WithdrawViewholders(View view) {
            super(view);
            tvcontent = (TextView) view.findViewById(R.id.tv_withdraw);

        }
    }

    class ToUserTransferViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private ImageView sendFailImg;
        private ImageView image_hb;
        private TextView chat_time;
        private TextView name;
        private TextView beizhu;
        private TextView txt_money;
        private RelativeLayout relative_transfer;
        private TextView buttom;

        public ToUserTransferViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            chat_time = (TextView) view.findViewById(R.id.mychat_time);
            beizhu = (TextView) view.findViewById(R.id.txt_beizhu);
            txt_money = (TextView) view.findViewById(R.id.txt_money);
            relative_transfer = (RelativeLayout) view.findViewById(R.id.relative_transfer);
            name = (TextView) view.findViewById(R.id.name);
            buttom = (TextView) view.findViewById(R.id.buttom);
            image_hb = (ImageView) view
                    .findViewById(R.id.image_hb);

        }
    }

    class FromUserTransferViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private ImageView sendFailImg;
        private TextView chat_time;
        private TextView name;
        private TextView beizhu;
        private TextView txt_money;
        private RelativeLayout relative_transfer;
        private TextView buttom;
        private ImageView image_hb;

        public FromUserTransferViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            image_hb = (ImageView) view
                    .findViewById(R.id.image_hb);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            beizhu = (TextView) view.findViewById(R.id.txt_beizhu);
            txt_money = (TextView) view.findViewById(R.id.txt_money);
            relative_transfer = (RelativeLayout) view.findViewById(R.id.relative_transfer);
            name = (TextView) view.findViewById(R.id.name);
            buttom = (TextView) view.findViewById(R.id.buttom);
        }
    }

    class ToUserRedViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private ImageView sendFailImg;
        private TextView chat_time;
        private TextView name;
        private TextView beizhu;
        private RelativeLayout relative_redpacket;

        private ImageView image_hb;
        private TextView buttom;
        private TextView txt_go_detail;

        public ToUserRedViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            chat_time = (TextView) view.findViewById(R.id.mychat_time);
            beizhu = (TextView) view.findViewById(R.id.txt_beizhu);
            relative_redpacket = (RelativeLayout) view.findViewById(R.id.relative_redpacket);
            name = (TextView) view.findViewById(R.id.name);

            image_hb = (ImageView) view
                    .findViewById(R.id.image_hb);
            buttom = (TextView) view.findViewById(R.id.buttom);
            txt_go_detail = (TextView) view.findViewById(R.id.txt_go_detail);

        }
    }

    class FromUserRedViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private ImageView sendFailImg;
        private TextView chat_time;
        private TextView name;
        private TextView beizhu;
        private RelativeLayout relative_redpacket;
        private ImageView image_hb;
        private TextView buttom;
        private TextView txt_go_detail;


        public FromUserRedViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            beizhu = (TextView) view.findViewById(R.id.txt_beizhu);
            relative_redpacket = (RelativeLayout) view.findViewById(R.id.relative_redpacket);
            name = (TextView) view.findViewById(R.id.name);

            image_hb = (ImageView) view
                    .findViewById(R.id.image_hb);
            buttom = (TextView) view.findViewById(R.id.buttom);
            txt_go_detail = (TextView) view.findViewById(R.id.txt_go_detail);

        }
    }

    class PromptViewHolder extends RecyclerView.ViewHolder {
        private TextView txt_red_name;
        private ImageView image_hb;

        public PromptViewHolder(View view) {
            super(view);
            txt_red_name = (TextView) view.findViewById(R.id.txt_red_name);
            image_hb = (ImageView) view.findViewById(R.id.image_hb);
        }
    }

    class FromUserMsgViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private GifTextView content;
        //private GifTextView content_fy;
        //   private TextView button_fanyi;
        private TextView name;

        public FromUserMsgViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            content = (GifTextView) view.findViewById(R.id.content);
            // content_fy = (GifTextView) view.findViewById(R.id.content_fy);
            // button_fanyi = (TextView) view.findViewById(R.id.button_fanyi);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    class FromUserImageViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private TextView name;
        private BubbleImageView image_Msg;

        public FromUserImageViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            image_Msg = (BubbleImageView) view
                    .findViewById(R.id.image_message);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    class FromUserLocationViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private BubbleImageView image_Msg;
        private TextView tv_addr;
        private TextView name;

        public FromUserLocationViewHolder(View itemView) {
            super(itemView);

            headicon = (ImageView) itemView
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) itemView.findViewById(R.id.chat_time);
            image_Msg = (BubbleImageView) itemView
                    .findViewById(R.id.image_message);
            tv_addr = (TextView) itemView.findViewById(R.id.tv_addr);
            name = (TextView) itemView.findViewById(R.id.name);
        }


    }

    class FromUserVoiceViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private TextView name;
        private LinearLayout voice_group;
        private TextView voice_time;
        private FrameLayout voice_image;
        private View receiver_voice_unread;
        private View voice_anim;

        public FromUserVoiceViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_other_user_icon);
            chat_time = (TextView) view.findViewById(R.id.chat_time);
            voice_group = (LinearLayout) view
                    .findViewById(R.id.voice_group);
            voice_time = (TextView) view
                    .findViewById(R.id.voice_time);
            receiver_voice_unread = (View) view
                    .findViewById(R.id.receiver_voice_unread);
            voice_image = (FrameLayout) view
                    .findViewById(R.id.voice_receiver_image);
            voice_anim = (View) view
                    .findViewById(R.id.id_receiver_recorder_anim);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    class ToUserMsgViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private TextView name;
        private GifTextView content;
        private ImageView sendFailImg;

        public ToUserMsgViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            content = (GifTextView) view
                    .findViewById(R.id.mycontent);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    class ToUserImgViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private TextView name;
        private LinearLayout image_group;
        private BubbleImageView image_Msg;
        private ImageView sendFailImg;

        public ToUserImgViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            image_group = (LinearLayout) view
                    .findViewById(R.id.image_group);
            image_Msg = (BubbleImageView) view
                    .findViewById(R.id.image_message);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    class ToUserLocationViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private BubbleImageView image_Msg;
        private TextView tv_addr;
        private RelativeLayout image_group;
        private ImageView sendFailImg;

        public ToUserLocationViewHolder(View itemView) {
            super(itemView);
            headicon = (ImageView) itemView
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) itemView.findViewById(R.id.mychat_time);
            image_Msg = (BubbleImageView) itemView
                    .findViewById(R.id.image_message);
            tv_addr = (TextView) itemView.findViewById(R.id.tv_addr);

            sendFailImg = (ImageView) itemView
                    .findViewById(R.id.mysend_fail_img);
            image_group = (RelativeLayout) itemView
                    .findViewById(R.id.image_group);
        }
    }

    class ToUserVoiceViewHolder extends RecyclerView.ViewHolder {
        private ImageView headicon;
        private TextView chat_time;
        private TextView name;
        private LinearLayout voice_group;
        private TextView voice_time;
        private FrameLayout voice_image;
        private View receiver_voice_unread;
        private View voice_anim;
        private ImageView sendFailImg;

        public ToUserVoiceViewHolder(View view) {
            super(view);
            headicon = (ImageView) view
                    .findViewById(R.id.tb_my_user_icon);
            chat_time = (TextView) view
                    .findViewById(R.id.mychat_time);
            voice_group = (LinearLayout) view
                    .findViewById(R.id.voice_group);
            voice_time = (TextView) view
                    .findViewById(R.id.voice_time);
            voice_image = (FrameLayout) view
                    .findViewById(R.id.voice_image);
            voice_anim = (View) view
                    .findViewById(R.id.id_recorder_anim);
            sendFailImg = (ImageView) view
                    .findViewById(R.id.mysend_fail_img);
            name = (TextView) view.findViewById(R.id.name);
        }
    }

    /**
     * @param holder
     * @param position
     */
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ImMessage tbub = userList.get(position);
        int itemViewType = getItemViewType(position);
        switch (itemViewType) {
            case FROM_USER_MSG:
                fromMsgUserLayout((FromUserMsgViewHolder) holder, tbub, position);
                break;
            case FROM_USER_IMG:
                fromImgUserLayout((FromUserImageViewHolder) holder, tbub, position);
                break;
            case FROM_USER_VOICE:
                fromVoiceUserLayout((FromUserVoiceViewHolder) holder, tbub, position);
                break;
            case FROM_USER_REDPACKET:
                fromRedPacketUserLayout((FromUserRedViewHolder) holder, tbub, position);
                break;

            case TO_USER_MSG:
                toMsgUserLayout((ToUserMsgViewHolder) holder, tbub, position);
                break;
            case TO_USER_IMG:
                toImgUserLayout((ToUserImgViewHolder) holder, tbub, position);
                break;
            case TO_USER_VOICE:
                toVoiceUserLayout((ToUserVoiceViewHolder) holder, tbub, position);
                break;
            case TO_USER_REDPACKET:
                toRedPacketUserLayout((ToUserRedViewHolder) holder, tbub, position);
                break;
            case Send_lucky_Red_Envelopes:
                LuckyRedPackSendingLayout((LuckyRedPackSendingViewHolder) holder, tbub, position);
                break;
            case TO_USER_LOCATION:
                toLocationUserLayout((ToUserLocationViewHolder) holder, tbub, position);
                break;
            case FROM_USER_LOCATION:
                fromLocationUserLayout((FromUserLocationViewHolder) holder, tbub, position);
                break;
            case SHOW_PROMP_RED://用于红包领取提示
                PromptViewLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_PROMP_REDPACKET_NOFINISH://红包被抢光
                PromptViewLayout((PromptViewHolder) holder, tbub, SHOW_PROMP_REDPACKET_NOFINISH + 10000);
                break;
            case TO_USER_TRANSFER:
                toTransferUserLayout((ToUserTransferViewHolder) holder, tbub, position);
                break;
            case FROM_USER_TRANSFER:
                fromTransferUserLayout((FromUserTransferViewHolder) holder, tbub, position);
                break;
            case TO_USER_TRANSFER_OTHER_GET:
                toTransferUserLayout2((ToUserTransferViewHolder) holder, tbub, position);
                break;
            case FROM_USER_TRANSFER_OTHER_GET:
                fromTransferUserLayout2((FromUserTransferViewHolder) holder, tbub, position);
                break;
            case SHOW_PROMP_JOIN_GROUP://有人加入群组
                AddGroupViewLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_PROMP_DELETE_GROUP://有人退出群组
                DeleteGroupViewLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_SET_MANAGER://设置了管理员
                setManagerLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_CANCEL_MANAGER://取消了管理员
                cancelManagerLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_BEAN_REMOVE:
                beanRemovedLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_BEAN_INVITED_JOIN_GROUP:
                beInviteToJoinLayout((PromptViewHolder) holder, tbub, position);
                break;
            case SHOW_REDPACKET_BACK://红包退回
                RedPacketViewLayout((PromptViewHolder) holder, tbub, position);
                break;
            case TO_WITHDRAW_MSG://发送撤回
                towithdrawLayout((WithdrawViewholders) holder, tbub, position);
                break;
            case FROM_WITHDRAW_MSG://收到撤回
                fromwithdrawLayout((WithdrawViewholders) holder, tbub, position);
                break;
            case TO_USER_EMOJI://发送的表情
                touseremojiLayout((TouserEmojiViewHolder) holder, tbub, position);
                break;
            case FROM_USER_EMOJI://收到的表情
                fromuseremojiLayout((FromuserEmojiViewHolder) holder, tbub, position);
                break;
            case TO_USER_EMOJI_TEXT:
                touseremojitextLayout((TouserEmojitextViewHolder) holder, tbub, position);
                break;
            case FROM_USER_EMOJI_TEXT:
                fromuseremojitextLayout((FromuserEmojitextViewHolder) holder, tbub, position);
                break;
            case TO_USER_FILE://发文件
                touserFileLayout((TouserFileViewHolder) holder, tbub, position);
                break;
            case FROM_USER_FILE://收文件
                fromuserFileLayout((FromuserFileViewHolder) holder, tbub, position);
                break;
            case TO_USER_VEDIO://发小视屏
                touserVedioLayout((TouserVedioViewHolder) holder, tbub, position);
                break;
            case FROM_USER_VEDIO://收小视屏
                fromuserVedioLayout((FromuserVedioViewHolder) holder, tbub, position);
                break;
            case TO_USER_AA://AA收款
                touseraaLayout((ToAaViewHolder) holder, tbub, position);
                break;
            case FROM_USER_AA://AA付款
                fromuseraaLayout((FromAaViewHolder) holder, tbub, position);
                break;
            case Lucky_Red_Envelope://幸运红包
                LuckyRedPackInterface((LuckyRedPackReceivingViewHolder) holder, tbub, position);
                break;
            case TO_USER_READDELETE://发送阅后即焚
                touserreaddeleteLayout((ToreaddeleteHolder) holder, tbub, position);
                break;
            case FROM_USER_READDELETE://收到阅后即焚
                fromuserreaddeleteLayout((FromreaddeleteHolder) holder, tbub, position);
                break;
            case TO_USER_FRIEND_MP:
                setToUserFriendMp((FriendMPViewHolder) holder, tbub, position);
                break;
            case FROM_USER_FRIEND_MP:
                setFromUserFriendMp((FriendMPFromViewHolder) holder, tbub, position);
                break;
            default://未定义的类型
                nocaseLayout((WithdrawViewholders) holder);
                break;
        }
    }

    private void beInviteToJoinLayout(PromptViewHolder holder, ImMessage tbub, int position) {

        IMMessageUtil.setBeJoinGroupText(holder.txt_red_name,tbub.getContent(),tbub.getFromid());
    }

    private void beanRemovedLayout(PromptViewHolder holder, ImMessage tbub, int position) {

        JSONObject jsonObject = JSON.parseObject(tbub.getContent());
        String name = jsonObject.getString("name");
        if (StringUtils.isEmpty(name)) {
            name = context.getResources().getString(R.string.have_people);
        }
        List<GroupFriendEntivity> groupFriendEntivities3 = GroupFriendEntivity.find(GroupFriendEntivity.class,
                "belong_group_id=? and name=?", "" + tbub.getFromid(), name);
        if (null != groupFriendEntivities3 && groupFriendEntivities3.size() > 0 && ToolsUtils.getMyUserId().equals(String.valueOf(groupFriendEntivities3.get(0).getUid()))) {
            holder.txt_red_name.setText(R.string.you_has_bean_remove_from_group_chat);
        } else {
            holder.txt_red_name.setText(String.format("%s%s", name,
                    context.getResources().getString(R.string.has_bean_remove_from_group_chat)));
        }
    }

    private void setManagerLayout(PromptViewHolder holder, ImMessage tbub, int position) {

        holder.txt_red_name.setText(ToolsUtils.getManagerChangeTxt(context, tbub, true));
    }


    private void cancelManagerLayout(PromptViewHolder holder, ImMessage tbub, int position) {

        holder.txt_red_name.setText(ToolsUtils.getManagerChangeTxt(context, tbub, false));
    }

    private void setToUserFriendMp(ChatGroupRecyclerAdapter.FriendMPViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
         /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        /*已读未读*/
//        if (tbub.isRead()) {
//            holder.tvread.setText("已读");
//        } else {
//            holder.tvread.setText("未读");
//        }

        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;
            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        try {
            final FriendmpBean friendmpBean = new Gson().fromJson(tbub.getContent(), FriendmpBean.class);
            if (null != friendmpBean) {
                GlideUtils.loadImage(context, friendmpBean.getHeadUrl(), holder.image_head);
                holder.txt_name.setText(friendmpBean.getNickName());
                holder.txt_uid.setText("ID ：" + friendmpBean.getContactId());
            }
            holder.imview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != friendmpBean.getContactId() && !"".equals(friendmpBean.getContactId())) {
                        Intent intent = new Intent(context, FriendDetailActivity.class);
                        intent.putExtra("id", Long.parseLong(friendmpBean.getContactId()));
                        (context).startActivity(intent);
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    private void setFromUserFriendMp(ChatGroupRecyclerAdapter.FriendMPFromViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        boolean read = tbub.isRead();
        if (read) {//已读
        } else {
            if (tbub != null) {
                if (onReadAiteListenler != null) {
                    onReadAiteListenler.isRead(tbub);
                }
                EventBus.getDefault().post(context.getString(R.string.aiteisread));
            }
        }

        try {
            final FriendmpBean friendmpBean = new Gson().fromJson(tbub.getContent(), FriendmpBean.class);
            if (null != friendmpBean) {
                GlideUtils.loadImage(context, friendmpBean.getHeadUrl(), holder.image_head);
                holder.txt_name.setText(friendmpBean.getNickName());
                holder.txt_uid.setText("ID ：" + friendmpBean.getContactId());
            }
            holder.imview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != friendmpBean.getContactId() && !"".equals(friendmpBean.getContactId())) {
                        Intent intent = new Intent(context, FriendDetailActivity.class);
                        intent.putExtra("id", Long.parseLong(friendmpBean.getContactId()));
                        (context).startActivity(intent);
                    }

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void fromuserreaddeleteLayout(final FromreaddeleteHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.image_Msg.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("info", "按下");
                        onlongclicklistenler.longClick(holder.image_Msg, position, TO_USER_READDELETE);
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("info", "抬起");
                        if (onTouchUplistener != null) {
                            onTouchUplistener.onTouchup(position);
                        }
                        break;
                    case MotionEvent.AXIS_PRESSURE:
                        Log.i("info", "按下");
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        Log.i("info2", "333按下");
                        if (onTouchUplistener != null) {
                            onTouchUplistener.onTouchup(position);
                        }
                        return true;
                }
                return true;
            }
        });

//        }
        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);

    }

    private void touserreaddeleteLayout(final ToreaddeleteHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);
        holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

//        if (isPicRefresh) {
        holder.image_group.setVisibility(View.VISIBLE);
        holder.image_Msg.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("info", "按下");
                        onlongclicklistenler.longClick(holder.image_Msg, position, TO_USER_READDELETE);
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("info", "抬起");
                        if (onTouchUplistener != null) {
                            onTouchUplistener.onTouchup(position);
                        }
                        break;
                    case MotionEvent.AXIS_PRESSURE:
                        Log.i("info", "按下");
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        Log.i("info2", "333按下");
                        if (onTouchUplistener != null) {
                            onTouchUplistener.onTouchup(position);
                        }
                        return true;
                }
                return true;
            }
        });

    }
    /*
    AA收款
     */
    private void fromuseraaLayout(final FromAaViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1).getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        boolean payed = tbub.isPayed();
        if (payed) {
            holder.txt_money.setText(context.getResources().getString(R.string.pay_money_1));
        } else {
            holder.txt_money.setText(context.getResources().getString(R.string.pay_money_2));
        }
        String content = tbub.getContent();
        try {
            AAentivity aAentivity = new Gson().fromJson(content, AAentivity.class);
            String msg = aAentivity.getMsg();
            if (msg != null && !StringUtils.isEmpty(msg)) {
                holder.beizhu.setText(msg);
            } else {
                holder.beizhu.setText(context.getResources().getString(R.string.aa_brife));
            }
        } catch (Exception e) {

        }
        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AAActivity.class);
                intent.putExtra("data", tbub);
                intent.putExtra("tag", 2);
                context.startActivity(intent);
            }
        });
    }

    private void touseraaLayout(final ToAaViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        String content = tbub.getContent();
        try {
            AAentivity aAentivity = new Gson().fromJson(content, AAentivity.class);
            String msg = aAentivity.getMsg();
            if (msg != null && !StringUtils.isEmpty(msg)) {
                holder.beizhu.setText(msg);
            } else {
                holder.beizhu.setText(context.getResources().getString(R.string.aa_brife));
            }
        } catch (Exception e) {

        }
        // holder.txt_money.setText(getdoubTwoMoney(mTransferEntivity.getAmount()));
        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AAActivity.class);
                intent.putExtra("data", tbub);
                intent.putExtra("tag", 1);
                context.startActivity(intent);
                // onlongclickMsgListenler.msgLongClick(position,FROM_USER_AA,holder.relative_transfer);
            }
        });
    }

    private void fromuserVedioLayout(final FromuserVedioViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        String content = tbub.getContent();
        VedioEntity vedioEntity = new Gson().fromJson(content, VedioEntity.class);
        int vedioSize = vedioEntity.getVedioSize();//视屏时长
        SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
        String format = formatter.format(vedioSize);
        holder.tv_videotime.setText(format);
        int res;
        res = R.drawable.chatfrom_bg_focused;
        int width = DimenUtils.getScreenWidth() / Constant.CHAT_MESSAGE_IMG_SIZE_SCALE;
        Glide.with(context).load(vedioEntity.getGetVedioBitmapUrl()).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().into(holder.image_Msg);

        /*
        图片按比例缩放
         */
        SimpleTarget target = new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
                //这里我们拿到回掉回来的bitmap，可以加载到我们想使用到的地方
                ImageSize imageSize = MyBitmapUtil.getImageSize(bitmap);
                RelativeLayout.LayoutParams imageLP = (RelativeLayout.LayoutParams) (holder.image_Msg).getLayoutParams();
                imageLP.width = imageSize.getWidth();
                imageLP.height = imageSize.getHeight();
                holder.image_Msg.setLayoutParams(imageLP);

            }
        };
        Glide
                .with( context ) // could be an issue!
                .load( vedioEntity.getGetVedioBitmapUrl())
                .asBitmap()   //强制转换Bitmap
                .into( target );


        holder.image_Msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                stopPlayVoice();
                onclickDownloadListenler.clickDown(position, FROM_USER_VEDIO);
            }

        });
        holder.image_Msg.setOnLongClickListener(new View.OnLongClickListener() {//长按
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.image_Msg, position, FROM_USER_VEDIO);
                return true;
            }
        });
    }

    private void touserVedioLayout(final TouserVedioViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;
            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        String imageUrlSrc = "";
        String content = tbub.getContent();
        VedioEntity vedioEntity = new Gson().fromJson(content, VedioEntity.class);
        int vedioSize = vedioEntity.getVedioSize();//视屏时长
        SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
        String format = formatter.format(vedioSize);
        holder.tv_videotime.setText(format);

        if (tbub.getFilePath() != null && !tbub.getFilePath().equals("")) {
            String filePath = tbub.getFilePath();
            Log.i("info", "视频地址111" + filePath);
            Log.i("info", "视频时间222" + format);
            PathEntivity pathEntivity = new Gson().fromJson(filePath, PathEntivity.class);
            try {
                File file = new File(pathEntivity.getImgPath());
                if (file.exists()) {
                    imageUrlSrc = pathEntivity.getImgPath();
                } else{
                    imageUrlSrc = vedioEntity.getGetVedioBitmapUrl(); // 转发图片链接从这里取

                }
            } catch (Exception e) {
                imageUrlSrc = vedioEntity.getGetVedioBitmapUrl(); // 转发图片链接从这里取
            }
        } else {
            imageUrlSrc = vedioEntity.getGetVedioBitmapUrl(); // 转发图片链接从这里取
        }
        int res;
        res = R.drawable.chatto_bg_focused;
        int width = DimenUtils.getScreenWidth() / Constant.CHAT_MESSAGE_IMG_SIZE_SCALE;
        Glide.with(context).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.image_Msg);


        /*
        图片按比例缩放
         */
        SimpleTarget target = new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
                //这里我们拿到回掉回来的bitmap，可以加载到我们想使用到的地方
                ImageSize imageSize = MyBitmapUtil.getImageSize(bitmap);
                RelativeLayout.LayoutParams imageLP = (RelativeLayout.LayoutParams) (holder.image_Msg).getLayoutParams();
                imageLP.width = imageSize.getWidth();
                imageLP.height = imageSize.getHeight();
                holder.image_Msg.setLayoutParams(imageLP);

            }
        };
        Glide
                .with( context ) // could be an issue!
                .load( imageUrlSrc)
                .asBitmap()   //强制转换Bitmap
                .into( target );


        holder.image_Msg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {//
                stopPlayVoice();
                onclickDownloadListenler.clickDown(position, ChatRecyclerAdapter.TO_USER_VEDIO);
            }

        });
        holder.image_Msg.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.image_Msg, position, TO_USER_VEDIO);
                return true;
            }
        });
    }

    private void fromuserFileLayout(final FromuserFileViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        String content = tbub.getContent();
        try {
            final FileMsgEntivity fileMsgEntivity = new Gson().fromJson(content, FileMsgEntivity.class);
            String fileName = fileMsgEntivity.getFileName();
            String fileSize = fileMsgEntivity.getFileSize();
            boolean filished = fileMsgEntivity.isFilished();
            if (null != msgID && tbub.getMsgId().equals(msgID)) {
                if (progressint == 0) {
                    holder.progressBar.setVisibility(View.GONE);
                } else {
                    Log.i("info", "显示进度progressstr=" + progressstr);
                    holder.progressBar.setVisibility(View.VISIBLE);
                    holder.progressBar.setProgress(progressint);
                    holder.tvFileState.setText(progressstr + "%");
                    if (progressint == 100) {
                        holder.tvFileState.setText(context.getResources().getString(R.string.down_yes));
                        holder.progressBar.setVisibility(View.GONE);
                    }
                }
            }
            if (filished) {
                Log.i("info", "filished==" + filished);
                holder.tvFileState.setText(context.getResources().getString(R.string.down_yes));
                holder.progressBar.setVisibility(View.GONE);
            } else {
                holder.tvFileState.setText(context.getResources().getString(R.string.down_no));//如果未下载点击下载
            }
            holder.tvFilename.setText(fileName);
            holder.tvFilesize.setText(fileSize);
            holder.filelayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    stopPlayVoice();
                    String fileUrl = tbub.getFilePath();
                    if (fileMsgEntivity.isFilished()) {//下载完成了
                        if (fileUrl != null) {
                            Intent intent = ToolsUtils.openFile(fileUrl);
                            if (intent != null) {
                                context.startActivity(intent);
                            } else {
                                Toast.makeText(context, context.getResources().getString(R.string.file_no), Toast.LENGTH_SHORT).show();
                            }
                        }
                    } else {//未下载点击下载
                        onclickDownloadListenler.clickDown(position, FROM_USER_FILE);
                    }
                }
            });
            holder.filelayout.setOnLongClickListener(new View.OnLongClickListener() {//长按
                @Override
                public boolean onLongClick(View view) {
                    onlongclicklistenler.longClick(holder.filelayout, position, FROM_USER_FILE);
                    return true;
                }
            });
        } catch (Exception e) {

        }
    }

    private void touserFileLayout(final TouserFileViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;
            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        String content = tbub.getContent();
        try {
            FileMsgEntivity fileMsgEntivity = new Gson().fromJson(content, FileMsgEntivity.class);
            String fileName = fileMsgEntivity.getFileName();
            String fileSize = fileMsgEntivity.getFileSize();
            boolean filished = fileMsgEntivity.isFilished();
            if (filished) {
                holder.tvFileState.setText(context.getResources().getString(R.string.send_yes));
                holder.progressBar.setVisibility(View.GONE);
            }
            holder.tvFilename.setText(fileName);
            holder.tvFilesize.setText(fileSize);
        } catch (Exception e) {

        }
        if (null != msgID && tbub.getMsgId().equals(msgID)) {
            if (progressint == 0) {
                holder.progressBar.setVisibility(View.GONE);
            } else {
                holder.tvFileState.setText(progressstr + "%");
                holder.progressBar.setProgress(progressint);
                holder.progressBar.setVisibility(View.VISIBLE);
                if (progressint == 100) {
                    holder.tvFileState.setText(context.getResources().getString(R.string.send_yes));
                    holder.progressBar.setVisibility(View.GONE);
                }
            }
        }
        // holder.progressBar.setProgress(1);
        holder.image_group.setVisibility(View.VISIBLE);
        holder.image_group.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {//
                stopPlayVoice();
                onclickDownloadListenler.clickDown(position, TO_USER_FILE);
            }

        });
        holder.image_group.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.image_group, position, TO_USER_FILE);
                return true;
            }
        });

    }

    private void nocaseLayout(WithdrawViewholders holder) {
        holder.tvcontent.setText(context.getResources().getString(R.string.not_know_type_message));
        holder.tvcontent.setVisibility(View.GONE);
    }

    //撤回消息
    private void towithdrawLayout(WithdrawViewholders holder, ImMessage tbub, int position) {
        holder.tvcontent.setText(context.getResources().getString(R.string.uwithdrawamsg));
    } //撤回消息

    private void fromwithdrawLayout(WithdrawViewholders holder, ImMessage tbub, int position) {
        holder.tvcontent.setText("\"" + tbub.getFromname() + "\"" + context.getResources().getString(R.string.withdrawamsg));
    }

    @Override
    public int getItemViewType(int position) {
        return userList.get(position).getType();
    }

    @Override
    public int getItemCount() {
        return userList.size();
    }

    private void fromuseremojiLayout(final FromuserEmojiViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        holder.content.setVisibility(View.VISIBLE);
        final String content = tbub.getContent();
        try {
            MsgEntity msgentity = new Gson().fromJson(content, MsgEntity.class);
            if (msgentity.getMsgCodes() != null && !"".equals(msgentity.getMsgCodes())) {
                JSONArray array = new JSONArray(msgentity.getMsgCodes());
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ScreenUtil.dp2px(100), ScreenUtil.dp2px(100));
                lp.rightMargin = ScreenUtil.dp2px(10);
                holder.content.setLayoutParams(lp);
                holder.linear_content.setBackgroundResource(R.color.chat_backgroud);
                holder.content.showMessage(msgentity.getMsgString(), msgentity.getMsgType(), array);
                holder.content.setStickerSize(ScreenUtil.dp2px(100));

            } else {

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        holder.content.setTag(position);
        if (null == tbub.getIsShowFY() || !"1".equals(tbub.getIsShowFY())) {//不显示翻译
            holder.content_fy.setVisibility(View.GONE);
        } else {//显示翻译
            holder.content_fy.setVisibility(View.VISIBLE);
            FanYiBean mFanYi = new Gson().fromJson(tbub.getContent_fy(), FanYiBean.class);
            if (mFanYi != null) {
                holder.content_fy.setText(mFanYi.getTrans_result().get(0).getDst());
            } else {
                holder.content_fy.setText(content);
            }


        }
        holder.content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.content, position, FROM_USER_EMOJI_TEXT);
                return true;
            }
        });

       /* holder.button_fanyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null == tbub.getIsShowFY() || !"1".equals(tbub.getIsShowFY())) {//翻译
                    if (null == tbub.getContent_fy() || "".equals(tbub.getContent_fy())) {
                        mFanYiOnClick.fanYiOnClick(content, position, 0);
                    } else {
                        mFanYiOnClick.fanYiOnClick("", position, 1);
                    }
                } else {//隐藏
                    mFanYiOnClick.fanYiOnClick("", position, 2);
                }

            }
        });*/
    }

    private void fromuseremojitextLayout(final FromuserEmojitextViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        if (null != mImGroupEntivity&& "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        holder.content.setVisibility(View.VISIBLE);
        final String content = tbub.getContent();
        Log.i("info", "收到的表情消息==" + content);
        boolean read = tbub.isRead();
        if (read) {//已读
        } else {
            if (tbub != null) {
                if (onReadAiteListenler != null) {
                    onReadAiteListenler.isRead(tbub);
                }
                EventBus.getDefault().post(context.getString(R.string.aiteisread));
            }
        }
        MsgEntity msgentity = null;

        try {
            msgentity = new Gson().fromJson(content, MsgEntity.class);
            if (msgentity.getMsgCodes() != null && !"".equals(msgentity.getMsgCodes())) {
            } else {
                if (null != msgentity.getAiteId() && msgentity.getAiteId().size() > 0) {
                    for (int i = 0; i < msgentity.getAiteId().size(); i++) {
                        Long aLong = msgentity.getAiteId().get(i);
                        if (("" + aLong).equals(ToolsUtils.getMyUserId())) {//这里艾特了你
                        }
                    }
                }
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                //params.setMargins(ScreenUtil.dp2px(3), ScreenUtil.dp2px(1), ScreenUtil.dp2px(3),ScreenUtil.dp2px(1));
                holder.content.setLayoutParams(params);
                holder.linear_content.setBackgroundResource(R.drawable.chatfrom_bg_focused);
                holder.content.setText(msgentity.getMsgString());
                holder.content.setStickerSize(ScreenUtil.dp2px(40));
            }
        } catch (Exception e) {
            Log.i("info", "", e);
        }

        holder.content.setTag(position);
        holder.button_fanyi.setVisibility(View.VISIBLE);
        final String strcontent = null == msgentity ? content : msgentity.getMsgString();
        if (null == tbub.getIsShowFY() || !"1".equals(tbub.getIsShowFY())) {//不显示翻译
            holder.content_fy.setVisibility(View.GONE);
            holder.button_fanyi.setText(context.getResources().getString(R.string.chat_button_fanyi));
        } else {//显示翻译
            holder.content_fy.setVisibility(View.VISIBLE);
            FanYiBean mFanYi = new Gson().fromJson(tbub.getContent_fy(), FanYiBean.class);
            if (mFanYi != null) {
                holder.content_fy.setText(mFanYi.getTrans_result().get(0).getDst());
            } else {
                holder.content_fy.setText(strcontent);
            }

            holder.button_fanyi.setText(context.getResources().getString(R.string.chat_button_yinc));

        }
        holder.content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.content, position, FROM_USER_EMOJI_TEXT);
                return true;
            }
        });

        holder.button_fanyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null == tbub.getIsShowFY() || !"1".equals(tbub.getIsShowFY())) {//翻译
                    if (null == tbub.getContent_fy() || "".equals(tbub.getContent_fy())) {
                        mFanYiOnClick.fanYiOnClick(strcontent, position, 0);
                    } else {
                        mFanYiOnClick.fanYiOnClick("", position, 1);
                    }
                } else {//隐藏
                    mFanYiOnClick.fanYiOnClick("", position, 2);
                }

            }
        });
    }

    private void touseremojitextLayout(final TouserEmojitextViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;
            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.content.setVisibility(View.VISIBLE);
        holder.content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.content, position, FROM_USER_EMOJI_TEXT);
                return true;
            }
        });
        final String content = tbub.getContent();
        try {
            //加橙色背景
            MsgEntity msgentity = new Gson().fromJson(content, MsgEntity.class);
            if (msgentity.getMsgCodes() != null && !"".equals(msgentity.getMsgCodes())) {
            } else {
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                params.setMargins(ScreenUtil.dp2px(3), ScreenUtil.dp2px(1), ScreenUtil.dp2px(3), ScreenUtil.dp2px(1));
                holder.content.setLayoutParams(params);
                holder.content.setBackgroundResource(R.drawable.chatto_bg_focused);
                holder.content.setText(msgentity.getMsgString());
                holder.content.setStickerSize(ScreenUtil.dp2px(40));
            }
        } catch (Exception e) {

        }

    }

    private void touseremojiLayout(final TouserEmojiViewHolder holder, ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;
            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.content.setVisibility(View.VISIBLE);
        holder.content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(holder.content, position, FROM_USER_EMOJI_TEXT);
                return true;
            }
        });
//        holder.content.setSpanText(handler, tbub.getContent(), false);
//        holder.content.insertGif(convertNormalStringToSpannableString(tbub.getContent()));
        final String content = tbub.getContent();
        // Log.i("info","收到的表情消息=="+content);
        try {
            MsgEntity msgentity = new Gson().fromJson(content, MsgEntity.class);
            if (msgentity.getMsgCodes() != null && !"".equals(msgentity.getMsgCodes())) {
                JSONArray array = new JSONArray(msgentity.getMsgCodes());
               /* LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                params.setMargins(0, 0, ScreenUtil.dp2px(10), 0);
                holder.content.setLayoutParams(params);*/
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ScreenUtil.dp2px(100), ScreenUtil.dp2px(100));
                lp.rightMargin = ScreenUtil.dp2px(10);
                holder.content.setLayoutParams(lp);
                holder.content.setBackgroundResource(R.color.chat_backgroud);
                holder.content.showMessage(msgentity.getMsgString(), msgentity.getMsgType(), array);
                holder.content.setStickerSize(ScreenUtil.dp2px(100));
                Log.i("info", "iiii==" + array);
            } else {

            }
        } catch (Exception e) {

        }
    }

    private void fromMsgUserLayout(final FromUserMsgViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);

        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        holder.content.setVisibility(View.VISIBLE);
        holder.content.setSpanText(handler, tbub.getContent(), false);
        holder.content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, FROM_USER_MSG);
                return true;
            }
        });
       /* if (null == tbub.getIsShowFY() || !"1".equals(tbub.getIsShowFY())) {//不显示翻译
            holder.content_fy.setVisibility(View.GONE);
           // holder.button_fanyi.setText(context.getResources().getString(R.string.chat_button_fanyi));
        } else {//显示翻译
            holder.content_fy.setVisibility(View.VISIBLE);
            FanYiBean mFanYi = new Gson().fromJson(tbub.getContent_fy(), FanYiBean.class);
            if (mFanYi != null) {
                holder.content_fy.setText(mFanYi.getTrans_result().get(0).getDst());
            } else {
                holder.content_fy.setText(tbub.getContent());
            }
          //  holder.button_fanyi.setText(context.getResources().getString(R.string.chat_button_yinc));

        }*/

        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
    }

    private void fromImgUserLayout(final FromUserImageViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
//        if (isPicRefresh) {
        String imageUrlSrc = null;
        ImageSendEntity sendEntity = JsonUtil.toObject(tbub.getContent(),ImageSendEntity.class);
        if(sendEntity != null){
            imageUrlSrc = sendEntity.getImagePath();
        }
        if (imageUrlSrc != null && imageUrlSrc.contains(".gif")) {
            Glide.with(context.getApplicationContext()).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.NONE).dontAnimate().into(holder.image_Msg);

        } else {
            Glide.with(context.getApplicationContext()).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().into(holder.image_Msg);
        }
        final boolean canForward = sendEntity == null || sendEntity.isCanForward();
        holder.image_Msg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // TODO Auto-generated method stub
                stopPlayVoice();
                /*Intent intent = new Intent(context, ImageViewActivity.class);
                intent.putStringArrayListExtra("images", imageList);
                intent.putExtra("clickedIndex", imagePosition.get(position));
                context.startActivity(intent);*/
                ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());
                ImagePagerActivity.startImagePagerActivity((context), imageList, imagePosition.get(position), imageSize);
            }

        });
        holder.image_Msg.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, FROM_USER_IMG);
                return true;
            }
        });
//        }
        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);

    }

    private void fromVoiceUserLayout(final FromUserVoiceViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.voice_group.setVisibility(View.VISIBLE);
        if (holder.receiver_voice_unread != null)
            holder.receiver_voice_unread.setVisibility(View.GONE);
        if (holder.receiver_voice_unread != null && unReadPosition != null) {
            for (String unRead : unReadPosition) {
                if (unRead.equals(position + "")) {
                    holder.receiver_voice_unread
                            .setVisibility(View.VISIBLE);
                    break;
                }
            }
        }
        AnimationDrawable drawable;
        holder.voice_anim.setId(position);
        if (position == voicePlayPosition) {
            holder.voice_anim
                    .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
            holder.voice_anim
                    .setBackgroundResource(R.drawable.voice_play_receiver);
            drawable = (AnimationDrawable) holder.voice_anim
                    .getBackground();
            drawable.start();
        } else {
            holder.voice_anim
                    .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
        }
        holder.voice_group.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, FROM_USER_VOICE);
                return true;
            }
        });
        holder.voice_group.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (holder.receiver_voice_unread != null)
                    holder.receiver_voice_unread.setVisibility(View.GONE);
                holder.voice_anim
                        .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
                if (position == voicePlayPosition) {
                    stopPlayVoice();
                } else {
                    stopPlayVoice();
                    voicePlayPosition = holder.voice_anim.getId();
                    String voicePath = tbub.getUserVoiceUrl() == null ? "" : tbub
                            .getUserVoiceUrl();

//                if (!voicePath.equals("")) {
//                    String filePath = ToolsUtils.getPathFileName(voicePath);
//                    File file = new File(filePath);
//                    if (FileSaveUtil.isFileExists(file)) {
//                        AnimationDrawable drawable;
//                        holder.voice_anim
//                                .setBackgroundResource(R.drawable.voice_play_receiver);
//                        drawable = (AnimationDrawable) holder.voice_anim
//                                .getBackground();
//                        drawable.start();
//
//                        if (voiceIsRead != null) {
//                            voiceIsRead.voiceOnClick(position);
//                        }
//                        MediaManager.playSound(file.getPath(),
//                                new MediaPlayer.OnCompletionListener() {
//
//                                    @Override
//                                    public void onCompletion(MediaPlayer mp) {
//                                        voicePlayPosition = -1;
//                                        holder.voice_anim
//                                                .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
//                                    }
//                                });
//                    } else {
//                        new Thread(new Runnable() {
//                            @Override
//                            public void run() {
//                                HttpAssist.fileDown(tbub.getUserVoiceUrl(), mHandler, position);
//                            }
//                        }).start();
//                    }
//                }
                    AnimationDrawable drawable;
                    holder.voice_anim
                            .setBackgroundResource(R.drawable.voice_play_receiver);
                    drawable = (AnimationDrawable) holder.voice_anim
                            .getBackground();
                    drawable.start();

                    if (voiceIsRead != null) {
                        voiceIsRead.voiceOnClick(position);
                    }
                    EventBus.getDefault().post(Constant.STAR_PLAY_VOICE);
                    MediaManager.playSound(context, voicePath,
                            new MediaPlayer.OnCompletionListener() {

                                @Override
                                public void onCompletion(MediaPlayer mp) {
                                    stopPlayVoice();
                                    voicePlayPosition = -1;
                                    EventBus.getDefault().post(Constant.STOP_PLAY_VOICE);
                                    holder.voice_anim
                                            .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
                                }
                            }, AudioManager.STREAM_MUSIC);
                }
            }

        });
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case Constant.ADAPTER_VOICE_FROM_DOWN_FINISH:
                        if (msg.arg1 == position) {
                            AnimationDrawable drawable;
                            holder.voice_anim
                                    .setBackgroundResource(R.drawable.voice_play_receiver);
                            drawable = (AnimationDrawable) holder.voice_anim
                                    .getBackground();
                            drawable.start();

                            if (voiceIsRead != null) {
                                voiceIsRead.voiceOnClick(position);
                            }
                            MediaManager.playSound(context, (String) msg.obj,
                                    new MediaPlayer.OnCompletionListener() {

                                        @Override
                                        public void onCompletion(MediaPlayer mp) {
                                            voicePlayPosition = -1;
                                            holder.voice_anim
                                                    .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
                                        }
                                    }, AudioManager.STREAM_MUSIC);
                        }
                        break;
                }
            }
        };
        float voiceTime = tbub.getUserVoiceTime();
        BigDecimal b = new BigDecimal(voiceTime);
        float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
        holder.voice_time.setText(f1 + "\"");
        ViewGroup.LayoutParams lParams = holder.voice_image
                .getLayoutParams();
        lParams.width = (int) (mMinItemWith + mMaxItemWith / 60f
                * tbub.getUserVoiceTime());
        holder.voice_image.setLayoutParams(lParams);
        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);

    }

    private void fromLocationUserLayout(final FromUserLocationViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
       /* holder.headicon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mHeadUserOnClick.detailsOnClick(position, 0);
            }
        });*/
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        int res;
        String content = tbub.getContent();
        try {
            final LocationEntivity locationentivity = new Gson().fromJson(content, LocationEntivity.class);
            holder.tv_addr.setText(locationentivity.getAddr());

            res = R.drawable.chatfrom_bg_focused;
            //int width = DimenUtils.getScreenWidth() / Constant.CHAT_MESSAGE_IMG_SIZE_SCALE;
            Glide.with(context).load(locationentivity.getUrl()).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(holder.image_Msg);
            holder.image_Msg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    stopPlayVoice();
                    toLocationActivity(locationentivity.getLat(), locationentivity.getLut(), locationentivity.getAddr());
               /* Intent intent = new Intent(context, ImageViewActivity.class);
                intent.putStringArrayListExtra("images", imageList);
                intent.putExtra("clickedIndex", imagePosition.get(position));
                context.startActivity(intent);*/
                }

            });
        } catch (Exception e) {

        }
        holder.image_Msg.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, FROM_USER_LOCATION);
                return true;
            }
        });
    }

    private void toLocationUserLayout(final ToUserLocationViewHolder holder, final ImMessage tbub, final int position) {
        // int width = DimenUtils.getScreenWidth() / Constant.CHAT_MESSAGE_IMG_SIZE_SCALE;
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);//加载头像
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;
            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;
            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.image_group.setVisibility(View.VISIBLE);

        String imageUrlSrc = "";
        if (tbub.getFilePath() != null && !tbub.getFilePath().equals("")) {
            imageUrlSrc = tbub.getFilePath();
        } else if (tbub.getFileUrl() != null) {
            imageUrlSrc = tbub.getFileUrl();
        }
        final String content = tbub.getContent();
        Log.i("info", "==content==" + content);
        Log.i("info", "==content==" + content);
        try {
            LocationEntivity locationE = new Gson().fromJson(content, LocationEntivity.class);
            imageUrlSrc = locationE.getUrl();
            holder.tv_addr.setText(locationE.getAddr());
        } catch (Exception e) {
        }
        int res;
        res = R.drawable.chatto_bg_focused;
        Glide.with(context).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.RESULT).dontAnimate().into(holder.image_Msg);
        holder.image_Msg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                stopPlayVoice();
                if (!content.contains("storage")) {
                    LocationEntivity locationEntivity = new Gson().fromJson(content, LocationEntivity.class);
                    if (locationEntivity != null) {
                        toLocationActivity(locationEntivity.getLat(), locationEntivity.getLut(), locationEntivity.getAddr());
                    }
                }
                /*Intent intent = new Intent(context, ImageViewActivity.class);
                intent.putStringArrayListExtra("images", imageList);
                intent.putExtra("clickedIndex", imagePosition.get(position));
                context.startActivity(intent);*/
            }

        });
        holder.image_Msg.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, TO_USER_LOCATION);
                return true;
            }
        });


    }

    private void toMsgUserLayout(final ToUserMsgViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
//            holder.name.setText(tbub.getFromname());
            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        }

        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.content.setVisibility(View.VISIBLE);
        holder.content.setSpanText(handler, tbub.getContent(), false);
        //  holder.content.setSpanText(handler, tbub.getContent(), false);
        holder.content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, TO_USER_MSG);
                return true;
            }
        });
    }

    private void toImgUserLayout(final ToUserImgViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);

        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
//            holder.name.setText(tbub.getFromname());
            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        }
        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime() + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

//        if (isPicRefresh) {
        holder.image_group.setVisibility(View.VISIBLE);

        String imageUrlSrc = "";
        if (tbub.getFilePath() != null && !tbub.getFilePath().equals("")) {
            imageUrlSrc = tbub.getFilePath();
        } else if (tbub.getFileUrl() != null) {
            imageUrlSrc = tbub.getFileUrl();
        } else {
            ImageSendEntity sendEntity = JsonUtil.toObject(tbub.getContent(), ImageSendEntity.class);
            if(sendEntity != null){
                imageUrlSrc = sendEntity.getImagePath(); // 转发图片链接从这里取
            }
        }
       /* int res;
        res = R.drawable.chatto_bg_focused;
        int width = DimenUtils.getScreenWidth() / Constant.CHAT_MESSAGE_IMG_SIZE_SCALE;*/
        if (imageUrlSrc.contains(".gif")) {
            Glide.with(context.getApplicationContext()).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.NONE).dontAnimate().into(holder.image_Msg);
        } else {
            Glide.with(context.getApplicationContext()).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().into(holder.image_Msg);

        }



        Glide.with(context.getApplicationContext()).load(imageUrlSrc).thumbnail(0.1f).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().into(holder.image_Msg);

        /*
        视频图片按比例缩放
         */
        SimpleTarget target = new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
                //这里我们拿到回掉回来的bitmap，可以加载到我们想使用到的地方
                ImageSize imageSize = MyBitmapUtil.getImageSize(bitmap);
                RelativeLayout.LayoutParams imageLP = (RelativeLayout.LayoutParams) (holder.image_Msg).getLayoutParams();
                imageLP.width = imageSize.getWidth();
                imageLP.height = imageSize.getHeight();
                holder.image_Msg.setLayoutParams(imageLP);

            }
        };
        Glide
                .with( context ) // could be an issue!
                .load( imageUrlSrc)
                .asBitmap()   //强制转换Bitmap
                .into( target );


        holder.image_Msg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                stopPlayVoice();
               /* Intent intent = new Intent(context, ImageViewActivity.class);
                intent.putStringArrayListExtra("images", imageList);
                intent.putExtra("clickedIndex", imagePosition.get(position));
                context.startActivity(intent);*/
                ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());
                if (imagePosition.get(position) != null) {
                    ImagePagerActivity.startImagePagerActivity((context), imageList, imagePosition.get(position), imageSize);
                }
            }

        });
        holder.image_Msg.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, TO_USER_IMG);
                return true;
            }
        });
//        }
    }

    private void toVoiceUserLayout(final ToUserVoiceViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);

        switch (tbub.getSendState()) {
            case Constant.SENDING:
                an = AnimationUtils.loadAnimation(context,
                        R.anim.update_loading_progressbar_anim);
                LinearInterpolator lin = new LinearInterpolator();
                an.setInterpolator(lin);
                an.setRepeatCount(-1);
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.loading);
                holder.sendFailImg.startAnimation(an);
                an.startNow();
                holder.sendFailImg.setVisibility(View.VISIBLE);
                break;

            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        holder.voice_group.setVisibility(View.VISIBLE);
        if (holder.receiver_voice_unread != null)
            holder.receiver_voice_unread.setVisibility(View.GONE);
        if (holder.receiver_voice_unread != null && unReadPosition != null) {
            for (String unRead : unReadPosition) {
                if (unRead.equals(position + "")) {
                    holder.receiver_voice_unread
                            .setVisibility(View.VISIBLE);
                    break;
                }
            }
        }
        AnimationDrawable drawable;
        holder.voice_anim.setId(position);
        if (position == voicePlayPosition) {
            holder.voice_anim.setBackgroundResource(R.drawable.adj);
            holder.voice_anim
                    .setBackgroundResource(R.drawable.voice_play_send);
            drawable = (AnimationDrawable) holder.voice_anim
                    .getBackground();
            drawable.start();
        } else {
            holder.voice_anim.setBackgroundResource(R.drawable.adj);
        }
        holder.voice_group.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onlongclicklistenler.longClick(view, position, TO_USER_VOICE);
                return true;
            }
        });
        holder.voice_group.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (holder.receiver_voice_unread != null)
                    holder.receiver_voice_unread.setVisibility(View.GONE);
                holder.voice_anim.setBackgroundResource(R.drawable.adj);

                if (position == voicePlayPosition) {
                    stopPlayVoice();
                } else {
                    stopPlayVoice();
                    voicePlayPosition = holder.voice_anim.getId();
                    AnimationDrawable drawable;
                    holder.voice_anim
                            .setBackgroundResource(R.drawable.voice_play_send);
                    drawable = (AnimationDrawable) holder.voice_anim
                            .getBackground();
                    drawable.start();
                    String voicePath = tbub.getFileUrl() == null ? ""
                            : tbub.getFileUrl();
                    if (voiceIsRead != null) {
                        voiceIsRead.voiceOnClick(position);
                    }
                    EventBus.getDefault().post(Constant.STAR_PLAY_VOICE);
                    MediaManager.playSound(context, voicePath,
                            new MediaPlayer.OnCompletionListener() {

                                @Override
                                public void onCompletion(MediaPlayer mp) {
                                    stopPlayVoice();
                                    voicePlayPosition = -1;
                                    EventBus.getDefault().post(Constant.STOP_PLAY_VOICE);
                                    holder.voice_anim
                                            .setBackgroundResource(R.drawable.adj);
                                }
                            }, AudioManager.STREAM_MUSIC);
                }
            }
        });
        float voiceTime = tbub.getUserVoiceTime();
        BigDecimal b = new BigDecimal(voiceTime);
        float f1 = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
        holder.voice_time.setText(f1 + "\"");
        ViewGroup.LayoutParams lParams = holder.voice_image
                .getLayoutParams();
        lParams.width = (int) (mMinItemWith + mMaxItemWith / 60f
                * tbub.getUserVoiceTime());
        holder.voice_image.setLayoutParams(lParams);
    }

    private void toRedPacketUserLayout(final ToUserRedViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);

        if (null != tbub) {
            RedPacketEntivity redPacketEntivity = ToolsUtils.getRedPacket(tbub.getContent());
            if (null != redPacketEntivity && "3".equals(redPacketEntivity.getRedPacketType())) {
                holder.image_hb.setBackgroundResource(R.drawable.small_hbimg_s);
                holder.txt_go_detail.setVisibility(View.GONE);
                holder.buttom.setText(context.getResources().getString(R.string.title_red_packet_kl));
            } else {
                holder.image_hb.setBackgroundResource(R.drawable.small_hbimg);
                holder.txt_go_detail.setVisibility(View.VISIBLE);
                holder.buttom.setText(context.getResources().getString(R.string.mobile_yx_red_package));
            }
        }

        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
//            holder.name.setText(tbub.getFromname());
            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        }

        switch (1) {
            case Constant.SENDING:
                break;
            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.relative_redpacket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mRedPacketOnClick && null != tbub) {
                    mRedPacketOnClick.redOnClick(tbub, 1);
                } else {
                    Log.i(TAG, "onClick: -----null-----mRedPacketOnClick-------");
                }
//                mRedPacketOnClick.redOnClick(tbub.getContent(), 1);
            }
        });
        RedPacketEntivity mRedPacketEntivity = new Gson().fromJson(tbub.getContent(), RedPacketEntivity.class);
        holder.beizhu.setText("".equals(mRedPacketEntivity.getMsg()) ? context.getString(R.string.ordinary_red_packet_messagemr) : mRedPacketEntivity.getMsg());
        //holder.beizhu.setText("".equals(mRedPacketEntivity.getMsg()) ? context.getString(R.string.ordinary_red_packet_messagemr) : mRedPacketEntivity.getMsg());

    }

    /*
        发送幸运红包
         */
    private void LuckyRedPackSendingLayout(final LuckyRedPackSendingViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        String content = tbub.getContent();
        try {
            AAentivity aAentivity = new Gson().fromJson(content, AAentivity.class);
            String msg = aAentivity.getMsg();
            if (msg != null && !StringUtils.isEmpty(msg)) {
                holder.beizhu.setText(msg);
            } else {
                holder.beizhu.setText(context.getResources().getString(R.string.luckyred_envelope_tips));
            }
        } catch (Exception e) {

        }
        // holder.txt_money.setText(getdoubTwoMoney(mTransferEntivity.getAmount()));
        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, LuckyRedEnvelopeActivity.class);
                intent.putExtra("data", tbub);
                intent.putExtra("tag", 1);
                context.startActivity(intent);
                // onlongclickMsgListenler.msgLongClick(position,FROM_USER_AA,holder.relative_transfer);
            }
        });
    }

    /*
    接收幸运红包
     */
    private void LuckyRedPackInterface(final LuckyRedPackReceivingViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1).getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        boolean payed = tbub.isPayed();
        if (payed) {
            holder.txt_money.setText(context.getResources().getString(R.string.already_involved));
        } else {
            holder.txt_money.setText(context.getResources().getString(R.string.pending_participation));
        }
        String content = tbub.getContent();
        try {
            LuckyRedEnvelopeEntivity luckyredenvelopeentivity = new Gson().fromJson(content, LuckyRedEnvelopeEntivity.class);
            String msg = luckyredenvelopeentivity.getContent();
            if (msg != null && !StringUtils.isEmpty(msg)) {
                holder.beizhu.setText(msg);
            } else {
                holder.beizhu.setText(context.getResources().getString(R.string.luckyred_envelope_tips));
            }
        } catch (Exception e) {

        }
       holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, LuckyRedEnvelopeActivity.class);
                intent.putExtra("data", tbub);
                intent.putExtra("tag", 2);
                context.startActivity(intent);
            }
        });
    }



    private void fromRedPacketUserLayout(final FromUserRedViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);

        if (null != tbub) {
            RedPacketEntivity redPacketEntivity = ToolsUtils.getRedPacket(tbub.getContent());
            if (null != redPacketEntivity && "3".equals(redPacketEntivity.getRedPacketType())) {
                holder.image_hb.setBackgroundResource(R.drawable.small_hbimg_s);
                holder.txt_go_detail.setVisibility(View.GONE);
                holder.buttom.setText(context.getResources().getString(R.string.title_red_packet_kl));
            } else {
                holder.image_hb.setBackgroundResource(R.drawable.small_hbimg);
                holder.txt_go_detail.setVisibility(View.VISIBLE);
                holder.buttom.setText(context.getResources().getString(R.string.mobile_yx_red_package));
            }
        }

        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1).getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
//        mRedPacketOnClick
        holder.relative_redpacket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mRedPacketOnClick && null != tbub) {
                    mRedPacketOnClick.redOnClick(tbub, 0);
                } else {
                    Log.i(TAG, "onClick: -----null-----mRedPacketOnClick-------");
                }

            }
        });

        RedPacketEntivity mRedPacketEntivity = new Gson().fromJson(tbub.getContent(), RedPacketEntivity.class);
        holder.beizhu.setText("".equals(mRedPacketEntivity.getMsg()) ? context.getString(R.string.ordinary_red_packet_messagemr) : mRedPacketEntivity.getMsg());

        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);

    }


    private void toTransferUserLayout(final ToUserTransferViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);

        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
//            holder.name.setText(tbub.getFromname());
            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        }
        switch (1) {
            case Constant.SENDING:
                break;
            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }

                });
                break;
            default:
                break;
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }

        holder.buttom.setText(context.getResources().getString(R.string.sam_trans));
        TransferEntivity mTransferEntivity = ToolsUtils.getTransfer(tbub.getContent());
        String beizhu = "";
        if (null != mTransferEntivity) {
            if (!StringUtils.isEmpty(mTransferEntivity.getMsg())) {
                beizhu = mTransferEntivity.getMsg();
            } else {
                beizhu = context.getResources().getString(R.string.look_detail);
            }
            holder.beizhu.setText(beizhu);
            holder.txt_money.setText(getdoubTwoMoney(mTransferEntivity.getAmount()));
        }

        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mRedPacketOnClick && null != tbub) {
                    mRedPacketOnClick.redOnClick(tbub, 3);
                } else {
                    Log.i(TAG, "onClick: -----null-----mRedPacketOnClick-------");
                }
//                mRedPacketOnClick.redOnClick(tbub.getContent(), 3);
            }
        });
    }

    private void toTransferUserLayout2(final ToUserTransferViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, ToolsUtils.getUser().getHeadUrl(), holder.headicon);

        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
//            holder.name.setText(tbub.getFromname());
            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        }
        switch (1) {
            case Constant.SENDING:
                break;
            case Constant.COMPLETED:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg.setVisibility(View.GONE);
                break;

            case Constant.SENDERROR:
                holder.sendFailImg.clearAnimation();
                holder.sendFailImg
                        .setBackgroundResource(R.drawable.msg_state_fail_resend_pressed);
                holder.sendFailImg.setVisibility(View.VISIBLE);
                holder.sendFailImg.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        if (sendErrorListener != null) {
                            sendErrorListener.onClick(position);
                        }
                    }
                });
                break;
            default:
                break;
        }

        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1)
                    .getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        TransferEntivity mTransferEntivity = ToolsUtils.getTransfer(tbub.getContent());
        if (null != mTransferEntivity) {
            holder.beizhu.setText(R.string.yet_receive_money);
            holder.txt_money.setText(mTransferEntivity.getAmount());
        }
        holder.image_hb.setBackgroundResource(R.drawable.shouqian);
        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mRedPacketOnClick && null != tbub) {
                    mRedPacketOnClick.redOnClick(tbub, 3);
                } else {
                    Log.i(TAG, "onClick: -----null-----mRedPacketOnClick-------");
                }
//                mRedPacketOnClick.redOnClick(tbub.getContent(), 3);
            }
        });
    }

    private void fromTransferUserLayout(final FromUserTransferViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1).getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        holder.buttom.setText(context.getResources().getString(R.string.sam_trans));
        TransferEntivity mTransferEntivity = ToolsUtils.getTransfer(tbub.getContent());
        if (null != mTransferEntivity) {
            if (StringUtils.isEmpty(mTransferEntivity.getMsg())) {
                holder.beizhu.setText(context.getResources().getString(R.string.look_detail));
            } else {
                holder.beizhu.setText(mTransferEntivity.getMsg());
            }
            holder.txt_money.setText(getdoubTwoMoney(mTransferEntivity.getAmount()));
        }

        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mRedPacketOnClick && null != tbub) {
                    mRedPacketOnClick.redOnClick(tbub, 2);
                } else {
                    Log.i(TAG, "onClick: -----null-----mRedPacketOnClick-------");
                }
//                mRedPacketOnClick.redOnClick(tbub.getContent(), 2);
            }
        });

        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);

    }

    /**
     * 转账被领取
     */
    private void fromTransferUserLayout2(final FromUserTransferViewHolder holder, final ImMessage tbub, final int position) {
        GlideUtils.loadHeadCircularImage(context, tbub.getImageIconUrl(), holder.headicon);
        if (null != mImGroupEntivity &&  "true".equals(mImGroupEntivity.getIsshowname())) {
            holder.name.setText(tbub.getFromname());
//            holder.name.setText(ToolsUtils.getNick(ToolsUtils.getUser()));
            holder.name.setVisibility(View.VISIBLE);
        } else {
            holder.name.setVisibility(View.GONE);
        }
        /* time */
        if (position != 0) {
            String showTime = getTime(tbub.getSendTime() + "", userList.get(position - 1).getSendTime() + "");
            if (showTime != null) {
                holder.chat_time.setVisibility(View.VISIBLE);
                holder.chat_time.setText(showTime);
            } else {
                holder.chat_time.setVisibility(View.GONE);
            }
        } else {
            String showTime = getTime(tbub.getSendTime()
                    + "", null);
            holder.chat_time.setVisibility(View.VISIBLE);
            holder.chat_time.setText(showTime);
        }
        TransferEntivity mTransferEntivity = ToolsUtils.getTransfer(tbub.getContent());
        if (null != mTransferEntivity) {
            holder.beizhu.setText(R.string.yet_receive_money);
            holder.txt_money.setText(mTransferEntivity.getAmount());
        }
        holder.image_hb.setBackgroundResource(R.drawable.shouqian);
        holder.relative_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mRedPacketOnClick && null != tbub) {
                    mRedPacketOnClick.redOnClick(tbub, 2);
                } else {
                    Log.i(TAG, "onClick: -----null-----mRedPacketOnClick-------");
                }
//                mRedPacketOnClick.redOnClick(tbub.getContent(), 2);
            }
        });
        // --------- 做头像点击事件-------
        holder.headicon.setTag(R.id.imageId, tbub.getDestid());
        holder.headicon.setOnClickListener(this);holder.headicon.setOnLongClickListener(this);
    }

    private void PromptViewLayout(final PromptViewHolder holder, final ImMessage tbub, final int position) {
        if (SHOW_PROMP_REDPACKET_NOFINISH + 10000 == position) {
            RedPacketEntivity mRed = new Gson().fromJson(tbub.getContent(), RedPacketEntivity.class);
            holder.txt_red_name.setText(context.getResources().getString(R.string.red_package) + ToolsUtils.getTimeString(Long.parseLong(mRed.getMsg()) / 1000) + context.getResources().getString(R.string.kill_and_loot));
        } else {
            if (("" + tbub.getDestid()).equals(ToolsUtils.getMyUserId())) {
                holder.txt_red_name.setText(R.string.you_receive_youself_red_package);
            } else {
                holder.txt_red_name.setText(tbub.getFromname() + context.getString(R.string.receive_your_red_package));
            }
        }
        holder.image_hb.setVisibility(View.VISIBLE);
    }

    private void AddGroupViewLayout(final PromptViewHolder holder, final ImMessage tbub, final int position) {
        ImFriendEntivity mmm = new Gson().fromJson(tbub.getContent(), ImFriendEntivity.class);
        String name = mmm.getName();
        if (null == name || "".equals(name)) {
            name = context.getResources().getString(R.string.have_people);
        }
//        String name = ToolsUtils.getGroupUserName(mFriendEntivities, tbub.getFromid());
        holder.txt_red_name.setText(name + context.getString(R.string.join_group));
    }

    private void DeleteGroupViewLayout(final PromptViewHolder holder, final ImMessage tbub, final int position) {
        ImFriendEntivity mmm = new Gson().fromJson(tbub.getContent(), ImFriendEntivity.class);
        String name = mmm.getName();
        if (null == name || "".equals(name)) {
            name = context.getResources().getString(R.string.have_people);
        }
        holder.txt_red_name.setText(name + context.getString(R.string.quit_group));
    }

    private void RedPacketViewLayout(final PromptViewHolder holder, final ImMessage tbub, final int position) {
        holder.txt_red_name.setText(R.string.red_package_overtime_balance_already_back);
    }

    /**
     * -------------点击监听--------------
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tb_other_user_icon:
                if (imageClickBack != null) {
                    imageClickBack.headImageClick(v, ((Long) v.getTag(R.id.imageId)));
                }
                break;
        }
    }


    @SuppressLint("SimpleDateFormat")
    public String getTime(String time, String before) {
        if ("".equals(time) || "0".equals(time) || time == null)
            time = returnTime();
        String show_time = null;
        if (before != null && !before.equals("0")) {
            try {
                if (time.length() == 13) {
                    SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    time = sDateFormat.format(new Date(Long.parseLong(time)));
                }
                if (before.length() == 13) {
                    SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    before = sDateFormat.format(new Date(Long.parseLong(before)));
                }
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                java.util.Date now = df.parse(time);
                java.util.Date date = df.parse(before);
                long l = now.getTime() - date.getTime();
                long day = l / (24 * 60 * 60 * 1000);
                long hour = (l / (60 * 60 * 1000) - day * 24);
                long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
                if (min >= 1) {
                    show_time = time.substring(11);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            if (time.length() > 11) {
                SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                time = sDateFormat.format(new Date(Long.parseLong(time)));
                show_time = time.substring(11);
            }
        }
        String getDay = getDay(time);
        if (show_time != null && getDay != null)
            show_time = getDay + " " + show_time;
        return show_time;
    }

    @SuppressLint("SimpleDateFormat")
    public static String returnTime() {
        SimpleDateFormat sDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm");
        String date = sDateFormat.format(new Date());
        return date;
    }

    @SuppressLint("SimpleDateFormat")
    public String getDay(String time) {
        String showDay = null;
        String nowTime = returnTime();

        if (null == time || time.equals("null") || "".equals(time))
            time = returnTime();
        try {
            if (time.length() == 13) {
                SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                time = sDateFormat.format(new Date(Long.parseLong(time)));
            }
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date now = df.parse(nowTime);
            Date date = df.parse(time);
            long l = now.getTime() - date.getTime();
            long day = l / (24 * 60 * 60 * 1000);
            if (day >= 365) {
                showDay = time.substring(0, 10);
            } else if (day >= 1 && day < 365) {
                showDay = time.substring(5, 10);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return showDay;
    }

    public static Bitmap getLoacalBitmap(String url) {
        try {
            ByteArrayOutputStream out;
            FileInputStream fis = new FileInputStream(url);
            BufferedInputStream bis = new BufferedInputStream(fis);
            out = new ByteArrayOutputStream();
            @SuppressWarnings("unused")
            int hasRead = 0;
            byte[] buffer = new byte[1024 * 2];
            while ((hasRead = bis.read(buffer)) > 0) {
                // 读出多少数据，向输出流中写入多少
                out.write(buffer);
                out.flush();
            }
            out.close();
            fis.close();
            bis.close();
            byte[] data = out.toByteArray();
            // 长宽减半
            BitmapFactory.Options opts = new BitmapFactory.Options();
            opts.inSampleSize = 3;
            return BitmapFactory.decodeByteArray(data, 0, data.length, opts);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onStopEvent(String code)//在ui线程执行
    {
        if (code.equals(Constant.STOP_VOICE_PLAY)) {
            stopPlayVoice();
        }
    }

    public void stopPlayVoice() {
        stopPlayVoice(true);
    }

    public void stopPlayVoice(boolean isShow) {
        if (isShow) EventBus.getDefault().post(Constant.STOP_PLAY_VOICE);
        if (voicePlayPosition != -1) {
            View voicePlay = (View) ((Activity) context)
                    .findViewById(voicePlayPosition);
            if (voicePlay != null) {
                if (getItemViewType(voicePlayPosition) == FROM_USER_VOICE) {
                    voicePlay
                            .setBackgroundResource(R.drawable.receiver_voice_node_playing003);
                } else {
                    voicePlay.setBackgroundResource(R.drawable.adj);
                }
            }
            MediaManager.pause();
            voicePlayPosition = -1;
        }
    }

    /**
     * 头像点击监听的接口
     */
    public interface IItemHeadImageClickBack {
        void headImageClick(View view, long idLong);
        void headImageLongClick(View view, long idLong);
    }

    //跳转位置定位页面
    private void toLocationActivity(double lat, double lut, String addr) {
        Intent intent = new Intent(context, ToLocationActivity.class);
        intent.putExtra("lat", lat);
        intent.putExtra("lut", lut);
        intent.putExtra("addr", addr);
        context.startActivity(intent);
    }

    public interface onLongClickMsgListenler {
        abstract void longClick(View view, int position, int type);
    }

    public interface onReadAiteListenler {
        abstract void isRead(ImMessage thub);
    }

    //幸运红包接收
    static class LuckyRedPackReceivingViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chat_time)
        TextView chat_time;
        @BindView(R.id.tb_other_user_icon)
        ImageView headicon;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.image_hb)
        ImageView imageHb;
        @BindView(R.id.txt_beizhu)
        TextView beizhu;
        @BindView(R.id.txt_money)
        TextView txt_money;
        @BindView(R.id.buttom)
        TextView buttom;
        @BindView(R.id.relative_transfer)
        RelativeLayout relative_transfer;

        public LuckyRedPackReceivingViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
    //幸运红包发送
    static class LuckyRedPackSendingViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.mychat_time)
        TextView chat_time;
        @BindView(R.id.tb_my_user_icon)
        ImageView headicon;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.mysend_fail_img)
        ImageView mysendFailImg;
        @BindView(R.id.image_hb)
        ImageView imageHb;
        @BindView(R.id.txt_beizhu)
        TextView beizhu;
        @BindView(R.id.txt_money)
        TextView txt_money;
        @BindView(R.id.buttom)
        TextView buttom;
        @BindView(R.id.relative_transfer)
        RelativeLayout relative_transfer;

        LuckyRedPackSendingViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }






    static class FromAaViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.chat_time)
        TextView chat_time;
        @BindView(R.id.tb_other_user_icon)
        ImageView headicon;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.image_hb)
        ImageView imageHb;
        @BindView(R.id.txt_beizhu)
        TextView beizhu;
        @BindView(R.id.txt_money)
        TextView txt_money;
        @BindView(R.id.buttom)
        TextView buttom;
        @BindView(R.id.relative_transfer)
        RelativeLayout relative_transfer;

        public FromAaViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    static class ToAaViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.mychat_time)
        TextView chat_time;
        @BindView(R.id.tb_my_user_icon)
        ImageView headicon;
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.mysend_fail_img)
        ImageView mysendFailImg;
        @BindView(R.id.image_hb)
        ImageView imageHb;
        @BindView(R.id.txt_beizhu)
        TextView beizhu;
        @BindView(R.id.txt_money)
        TextView txt_money;
        @BindView(R.id.buttom)
        TextView buttom;
        @BindView(R.id.relative_transfer)
        RelativeLayout relative_transfer;

        ToAaViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface OnTouchUplistener {
        void onTouchup(int position);
    }

    DecimalFormat df = new DecimalFormat("######0.00");

    private String getdoubTwoMoney(String inStr) {
        double money = 0;
        try {
            if (!"".equals(inStr)) {
                money = Double.parseDouble(inStr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return df.format(money);
    }

}
